import { contextBridge } from 'electron'
import { electronAPI } from '@electron-toolkit/preload'
import {ipcRenderer} from 'electron'

import {fileAPI} from './fileAPI'
import { postsAPI } from './postsAPI'
import { appConfig } from '../main/config'

// Custom APIs for renderer
const api = {
  ...fileAPI,
  ...postsAPI
}

// Use `contextBridge` APIs to expose Electron APIs to
// renderer only if context isolation is enabled, otherwise
// just add to the DOM global.
if (process.contextIsolated) {
  try {
    contextBridge.exposeInMainWorld('electron', electronAPI)
    contextBridge.exposeInMainWorld('api', api)
    contextBridge.exposeInMainWorld('appConfig', appConfig)

  } catch (error) {
    console.error(error)
  }
} else {
  window.electron = electronAPI
  window.api = api
  window.appConfig = appConfig
}


